use strict;
use warnings;

package Lingua::EN::WSD::WebBased::Seeder;

use List::MoreUtils qw/natatime/;
use Lingua::EN::WSD::WebBased::Logger;

use Class::AccessorMaker {
    sort_seeds      => 0
}, 'new_init';

sub init            { }
sub gen_seeds       { }
sub gen_query_core  { }

# to avoid query become too long

sub gen_seeds_disjunctions {
    
    my ($self, $target, $or_operator, $size) = @_;
    
    $or_operator    ||= 'OR';
    $size           ||= 40;

    my @seeds = @{$self->gen_seeds($target)};
    
    my $i = natatime $size, @seeds;
    my @disjunctions;
    while (my @s = $i->()) {
        my $disjunction = join " $or_operator ", map { qq/"$_"/ } @s;
        push @disjunctions, $disjunction;
    }

    return \@disjunctions;

}

# generate queries for a dmoz label

sub gen_queries {

    my ($self, $target, $and_operator, $or_operator, $size) = @_;

    $and_operator   ||= 'AND';
    $or_operator    ||= 'OR';
    $size           ||= 40;

    my $core = $self->gen_query_core($target);
    
    my @queries = map { qq/"$core" $and_operator ( $_ )/ } 
        @{$self->gen_seeds_disjunctions($target, $or_operator, $size)};

    @queries = (qq/"$core"/) if @queries == 0;
    
    return \@queries;

}

1;
